package com.ruoyi.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
        import com.ruoyi.common.utils.DateUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HomeUserMapper;
import com.ruoyi.system.domain.HomeUser;
import com.ruoyi.system.service.IHomeUserService;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2024-03-02
 */
@Service
public class HomeUserServiceImpl extends ServiceImpl<HomeUserMapper, HomeUser> implements IHomeUserService
{
    @Autowired
    private HomeUserMapper homeUserMapper;


    @Override
    public List<HomeUser> userList(HomeUser homeUser) {
        LambdaQueryWrapper<HomeUser> userLambdaQueryWrapper=new LambdaQueryWrapper<>();
        userLambdaQueryWrapper.orderByDesc(HomeUser::getCreateTime);
        userLambdaQueryWrapper.eq(ObjectUtils.isNotEmpty(homeUser.getPhoneNumber()),HomeUser::getPhoneNumber,homeUser.getPhoneNumber());
        userLambdaQueryWrapper.eq(ObjectUtils.isNotEmpty(homeUser.getIsSale()),HomeUser::getIsSale,homeUser.getIsSale());
        userLambdaQueryWrapper.eq(HomeUser::getIsDelete,0);
        List<HomeUser> homeUsers = homeUserMapper.selectList(userLambdaQueryWrapper);
        return homeUsers;
    }

    @Override
    public void userUpdate(Long id) {
        HomeUser homeUser = homeUserMapper.selectById(id);
        if (homeUser.getIsSale()==0){
            homeUser.setIsSale(1);
        }else {
            homeUser.setIsSale(0);
        }
        homeUserMapper.updateById(homeUser);
    }

    @Override
    public void deleteUser(Long id) {
        UpdateWrapper<HomeUser> userUpdateWrapper=new UpdateWrapper<>();
        userUpdateWrapper.lambda().eq(HomeUser::getId,id);
        userUpdateWrapper.set("is_delete",1);
        this.update(userUpdateWrapper);
    }
}
